local jinfa = fk.CreateSkill{
    name = "XD__jinfa"
}
Fk:loadTranslationTable{
    ["XD__jinfa"] = "进伐",
    [":XD__jinfa"] = "准备阶段开始时，你可令攻击范围内一名手牌多于你的角色对你使用一张【杀】（有距离限制），否则视为你对其使用一张【杀】；结束阶段开始时，你可令攻击范围内一名手牌少于你的角色对你使用一张【杀】（有距离限制），否则视为你对其使用一张【杀】。",
    ["#XD__jinfa"] = "是否发动 进伐，令一名角色除非对你使用【杀】，否则视为你对其使用【杀】",
    ["#XD__jinfa-use"] = "进伐：对 %src 使用一张【杀】，否则其视为对你使用【杀】",
}

jinfa:addEffect(fk.EventPhaseStart, {
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(jinfa.name) and (player.phase == Player.Start or player.phase == Player.Finish)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function (cp)
            if player:inMyAttackRange(cp) then
                if player.phase == Player.Start then
                    return cp:getHandcardNum() > player:getHandcardNum()
                else
                    return cp:getHandcardNum() < player:getHandcardNum()
                end
            end
        end)
        if #targets > 0 then
            local tos = room:askToChoosePlayers(player, {
                targets = targets,
                skill_name = jinfa.name,
                max_num = 1,
                min_num = 1,
                prompt = "#XD__jinfa",
            })
            if #tos > 0 then
                event:setCostData(self, {tos = tos})
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        local use = room:askToUseCard(to, {
            skill_name = jinfa.name,
            pattern = "slash",
            prompt = "#XD__jinfa-use:"..player.id,
            extra_data = {
                exclusive_targets = {player.id},
                bypass_times = true,
            }
        })
        if use then
            use.extraUse = true
            room:useCard(use)
        else
            room:useVirtualCard("slash", nil, player, {to}, jinfa.name, true)
        end
    end,
})

return jinfa